<%-- 
    Document   : admoEmpresas
    Created on : 18/06/2013, 03:15:40 PM
    Author     : Neto
--%>

<%@page contentType="text/html" pageEncoding="windows-1252"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <title>PRODUCTOS</title>
        <style>
            body{
                background-color: #B8ABAF;
            }
        </style>
        <link rel="STYLESHEET" type="text/css" href="${pageContext.request.contextPath}/resources/dhtmlxSuite/dhtmlxGrid/codebase/dhtmlxgrid.css">
        <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resources/dhtmlxSuite/dhtmlxGrid/codebase/skins/dhtmlxgrid_dhx_black.css">
        <script  src="${pageContext.request.contextPath}/resources/dhtmlxSuite/dhtmlxGrid//codebase/ext/dhtmlxgrid_rowspan.js"></script>
        <script  src="${pageContext.request.contextPath}/resources/dhtmlxSuite/dhtmlxGrid/codebase/dhtmlxcommon.js"></script>
        <script  src="${pageContext.request.contextPath}/resources/dhtmlxSuite/dhtmlxGrid/codebase/dhtmlxgrid.js"></script>
        <script  src="${pageContext.request.contextPath}/resources/dhtmlxSuite/dhtmlxGrid/codebase/ext/dhtmlxgrid_filter.js"></script>
        <script  src="${pageContext.request.contextPath}/resources/dhtmlxSuite/dhtmlxGrid/codebase/dhtmlxgridcell.js"></script> 
        <script  src="${pageContext.request.contextPath}/resources/dhtmlxSuite/dhtmlxGrid/codebase/ext/dhtmlxgrid_validation.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/resources/dhtmlxSuite/dhtmlxDataStore/codebase/datastore.js"></script>
    </head>
    <body>
        <table>
            <tr><th><h3 style="font-family: Tahoma; margin-left: 344px;">Productos</h3></th></tr>
            <tr>
                <td>
                  <div id="gridbox" style="width:600px; height:270px; margin-left: 360px;"></div>                        
                </td>
            </tr>
        </table>
       <!--  <input type="button" name="b1" value="add row" onClick="mygrid.addRow((new Date()).valueOf(),[1,2,'perro',4,5],1)"> -->
       <div style="width:600px; height:270px; margin-left: 560px; margin-top: 15px;">
        <button value="Insertar" onClick="inserta()">Insertar</button>
        <button value="Actualizar" onClick="actualiza()">Modificar</button>
        <button value="Borrar" onClick="elimina()">Borrar</button>
       </div>
        <script>
            var idGlobalDeLaFila=0;
            var nombre='';
            var detalles='';
            var precio='';
            var enVenta='';
            function elimina(){
                if(confirm('Esta seguro en eliminar la fila?')){
                dhtmlxAjax.post("../administrador/delete","clave="+idGlobalDeLaFila,function(loader){
                    alert("Fila elminada de la BD exitosamente!!!");
                    location.reload();
                });
                }
            } 
     
            function inserta(){
                dhtmlxAjax.post("../administrador/insertpro","claveCategoria=2&nombre=NombreProducto&detalles=DetallesProducto&precio=100&",function(loader){
                    alert("inserto!!");
                    location.reload();
                });
            } 
     
            function actualiza(){
                dhtmlxAjax.post("../administrador/update","clave="+idGlobalDeLaFila+"&claveCategoria=2&nombre="+nombre+"&detalles="+detalles+"&precio="+precio,function(loader){
                    alert("actualizo!!");
                    location.reload();
                });
            } 
             var data = new dhtmlXDataStore({
                url: "../administrador/mostrar",
                datatype: "json"
            });
            
            mygrid = new dhtmlXGridObject({
                parent:"gridbox",
                onRowSelect:function(){
			//alert("I'm clicked");	
		}
            });
            
            function doOnRowSelect(id) {
                var idFile= mygrid.getSelectedId();
                var d= mygrid.cells(idFile,0).getValue();
                idGlobalDeLaFila=d;
                nombre=mygrid.cells(idFile,2).getValue();
                detalles=mygrid.cells(idFile,3).getValue();
                precio=mygrid.cells(idFile,4).getValue();
                //alert(t);
            }
            mygrid.setImagePath("${pageContext.request.contextPath}/resources/dhtmlxSuite/dhtmlxGrid/codebase/imgs/");
            mygrid.setSkin("dhx_black");  
            mygrid.setHeader("Clave,Clave Categoria,Nombre,Detalles,precio");
            mygrid.setColAlign("left,left,center,center,right");
            mygrid.setColTypes("ed,ed,ed,ed,price");
            mygrid.setColSorting("int,int,str,str,int,int");
            mygrid.attachEvent("onRowSelect", doOnRowSelect);
            mygrid.setColumnIds("clave,claveCategoria,nombre,detalles,precio");
            mygrid.setColValidators([null,null,"NotEmpty","NotEmpty","ValidNumeric"]);
            //mygrid.enableAutoHeight(true)
            //mygrid.enableValidation(true, true, true, true,true);
            //mygrid.setColValidators([null,null,"Max15","Max35","Max10"]);
            
            mygrid.init();
            mygrid.sync(data, {
                sort: true,
                filter: true
            });
        </script>
    </body>
</html>
